package com.xxxx.server.controller;


import com.xxxx.server.pojo.Department;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-09-07
 */
@RestController
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "部门管理")
    @GetMapping("/system/basic/department")
    public List<Department> basicDepartment(){
        final List<Department> list = departmentService.getAllDept();
        return list;
    }

    @ApiOperation(value = "添加部门")
    @PostMapping("/system/basic/department")
    public RespBean doAddDep(@RequestBody Department department){
        //这里拿到需要添加的部门名称和该部门所依赖的部门
        boolean status = departmentService.AddDep(department);
        if(status){
            return RespBean.success("添加成功",department);
        }else{
            return RespBean.error("添加失败");
        }
    }

    @ApiOperation(value = "删除部门")
    @DeleteMapping("/system/basic/department/{id}")
    public RespBean doDelDep(@PathVariable("id") Integer id){
        boolean status = departmentService.delDep(id);
        if(status){
            return RespBean.success("删除成功");
        }else{
            return RespBean.error("删除失败");
        }
    }

}
